library(tidyverse) # for data cleaning and plotting
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.1.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(lubridate) # for date manipulation
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(openintro) # for the abbr2state() function
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
library(palmerpenguins)# for Palmer penguin data
library(maps) # for map data
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(ggmap) # for mapping points on maps
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(gplots) # for col2hex() function
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
library(RColorBrewer) # for color palettes
library(sf) # for working with spatial data
## Linking to GEOS 3.9.1, GDAL 3.4.0, PROJ 8.1.1; sf_use_s2() is TRUE
library(leaflet) # for highly customizable mapping
library(carData) # for Minneapolis police stops data
library(ggthemes) # for more themes (including theme_map())
theme_set(theme_minimal())
# Starbucks locations
Starbucks <- read_csv("https://www.macalester.edu/~ajohns24/Data/Starbucks.csv")
## Rows: 25600 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): Brand, Store Number, Store Name, Ownership Type, Street Address, C...
## dbl (2): Longitude, Latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
starbucks_us_by_state <- Starbucks %>%
filter(Country == "US") %>%
count(`State/Province`) %>%
mutate(state_name = str_to_lower(abbr2state(`State/Province`)))
# Lisa's favorite St. Paul places - example for you to create your own data
favorite_stp_by_lisa <- tibble(
place = c("Home", "Macalester College", "Adams Spanish Immersion",
"Spirit Gymnastics", "Bama & Bapa", "Now Bikes",
"Dance Spectrum", "Pizza Luce", "Brunson's"),
long = c(-93.1405743, -93.1712321, -93.1451796,
-93.1650563, -93.1542883, -93.1696608,
-93.1393172, -93.1524256, -93.0753863),
lat = c(44.950576, 44.9378965, 44.9237914,
44.9654609, 44.9295072, 44.9436813,
44.9399922, 44.9468848, 44.9700727)
)
#COVID-19 data from the New York Times
covid19 <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")
## Rows: 40774 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): state, fips
## dbl (2): cases, deaths
## date (1): date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
If you were not able to get set up on GitHub last week, go here and get set up first. Then, do the following (if you get stuck on a step, don’t worry, I will help! You can always get started on the homework and we can figure out the GitHub piece later):
keep_md: TRUE in the YAML heading. The .md file is a markdown (NOT R Markdown) file that is an interim step to creating the html file. They are displayed fairly nicely in GitHub, so we want to keep it and look at it there. Click the boxes next to these two files, commit changes (remember to include a commit message), and push them (green up arrow).Put your name at the top of the document.
For ALL graphs, you should include appropriate labels.
Feel free to change the default theme, which I currently have set to theme_minimal().
Use good coding practice. Read the short sections on good code with pipes and ggplot2. This is part of your grade!
When you are finished with ALL the exercises, uncomment the options at the top so your document looks nicer. Don’t do it before then, or else you might miss some important warnings and messages.
These exercises will reiterate what you learned in the “Mapping data with R” tutorial. If you haven’t gone through the tutorial yet, you should do that first.
ggmap)Starbucks locations to a world map. Add an aesthetic to the world map that sets the color of the points according to the ownership type. What, if anything, can you deduce from this visualization?world_map <- get_stamenmap(
bbox = c(left = -180, bottom = -57, right = 179, top = 82.1),
maptype = "terrain",
zoom = 2
)
## Source : http://tile.stamen.com/terrain/2/0/0.png
## Source : http://tile.stamen.com/terrain/2/1/0.png
## Source : http://tile.stamen.com/terrain/2/2/0.png
## Source : http://tile.stamen.com/terrain/2/3/0.png
## Source : http://tile.stamen.com/terrain/2/0/1.png
## Source : http://tile.stamen.com/terrain/2/1/1.png
## Source : http://tile.stamen.com/terrain/2/2/1.png
## Source : http://tile.stamen.com/terrain/2/3/1.png
## Source : http://tile.stamen.com/terrain/2/0/2.png
## Source : http://tile.stamen.com/terrain/2/1/2.png
## Source : http://tile.stamen.com/terrain/2/2/2.png
## Source : http://tile.stamen.com/terrain/2/3/2.png
ggmap(world_map)
#plotting the Starbucks data on my stamen map
ggmap(world_map) +
geom_point(data = Starbucks,
aes(x = Longitude,
y = Latitude,
color = `Ownership Type`),
alpha = .3,
size = .1) +
theme_map()
## Warning: Removed 1 rows containing missing values (geom_point).
mn_starbucks <- Starbucks %>%
filter(`State/Province` %in% "MN")
twin_cities_map <- get_stamenmap(
bbox = c(left = -94.4699, bottom = 44.4098, right = -91.6766, top = 45.4424),
maptype = "terrain",
zoom = 9)
## Source : http://tile.stamen.com/terrain/9/121/183.png
## Source : http://tile.stamen.com/terrain/9/122/183.png
## Source : http://tile.stamen.com/terrain/9/123/183.png
## Source : http://tile.stamen.com/terrain/9/124/183.png
## Source : http://tile.stamen.com/terrain/9/125/183.png
## Source : http://tile.stamen.com/terrain/9/121/184.png
## Source : http://tile.stamen.com/terrain/9/122/184.png
## Source : http://tile.stamen.com/terrain/9/123/184.png
## Source : http://tile.stamen.com/terrain/9/124/184.png
## Source : http://tile.stamen.com/terrain/9/125/184.png
## Source : http://tile.stamen.com/terrain/9/121/185.png
## Source : http://tile.stamen.com/terrain/9/122/185.png
## Source : http://tile.stamen.com/terrain/9/123/185.png
## Source : http://tile.stamen.com/terrain/9/124/185.png
## Source : http://tile.stamen.com/terrain/9/125/185.png
ggmap(twin_cities_map) +
geom_point(data = mn_starbucks,
aes(x = Longitude,
y = Latitude,
color = `Ownership Type`),
alpha = 1,
size = .7) +
theme_map()
## Warning: Removed 29 rows containing missing values (geom_point).
In the Twin Cities plot, play with the zoom number. What does it do? (just describe what it does - don’t actually include more than one map). The zoom number is connected to the amount of detail that will be shown in the mapping.
Try a couple different map types (see get_stamenmap() in help and look at maptype). Include a map with one of the other map types.
twin_cities_map <- get_stamenmap(
bbox = c(left = -94.4699, bottom = 44.4098, right = -91.6766, top = 45.4424),
maptype = "toner-2010",
zoom = 9)
## Source : http://tile.stamen.com/toner-2010/9/121/183.png
## Source : http://tile.stamen.com/toner-2010/9/122/183.png
## Source : http://tile.stamen.com/toner-2010/9/123/183.png
## Source : http://tile.stamen.com/toner-2010/9/124/183.png
## Source : http://tile.stamen.com/toner-2010/9/125/183.png
## Source : http://tile.stamen.com/toner-2010/9/121/184.png
## Source : http://tile.stamen.com/toner-2010/9/122/184.png
## Source : http://tile.stamen.com/toner-2010/9/123/184.png
## Source : http://tile.stamen.com/toner-2010/9/124/184.png
## Source : http://tile.stamen.com/toner-2010/9/125/184.png
## Source : http://tile.stamen.com/toner-2010/9/121/185.png
## Source : http://tile.stamen.com/toner-2010/9/122/185.png
## Source : http://tile.stamen.com/toner-2010/9/123/185.png
## Source : http://tile.stamen.com/toner-2010/9/124/185.png
## Source : http://tile.stamen.com/toner-2010/9/125/185.png
ggmap(twin_cities_map) +
geom_point(data = mn_starbucks,
aes(x = Longitude,
y = Latitude),
alpha = 1,
size = .7) +
theme_map()
## Warning: Removed 29 rows containing missing values (geom_point).
annotate() function (see ggplot2 cheatsheet).macalester_map <- get_stamenmap(
bbox = c(left = -93.4863, bottom = 44.8185, right = -92.7880, top = 45.0766),
maptype = "toner-2010",
zoom = 11)
## Source : http://tile.stamen.com/toner-2010/11/492/736.png
## Source : http://tile.stamen.com/toner-2010/11/493/736.png
## Source : http://tile.stamen.com/toner-2010/11/494/736.png
## Source : http://tile.stamen.com/toner-2010/11/495/736.png
## Source : http://tile.stamen.com/toner-2010/11/496/736.png
## Source : http://tile.stamen.com/toner-2010/11/492/737.png
## Source : http://tile.stamen.com/toner-2010/11/493/737.png
## Source : http://tile.stamen.com/toner-2010/11/494/737.png
## Source : http://tile.stamen.com/toner-2010/11/495/737.png
## Source : http://tile.stamen.com/toner-2010/11/496/737.png
## Source : http://tile.stamen.com/toner-2010/11/492/738.png
## Source : http://tile.stamen.com/toner-2010/11/493/738.png
## Source : http://tile.stamen.com/toner-2010/11/494/738.png
## Source : http://tile.stamen.com/toner-2010/11/495/738.png
## Source : http://tile.stamen.com/toner-2010/11/496/738.png
ggmap(macalester_map) +
geom_point(data = mn_starbucks,
aes(x = Longitude,
y = Latitude),
alpha = 1,
size = .7) +
annotate(geom = "text", y = 44.9379, x = -93.1691, label = "Macalester College") +
theme_map()
## Warning: Removed 85 rows containing missing values (geom_point).
geom_map())The example I showed in the tutorial did not account for population of each state in the map. In the code below, a new variable is created, starbucks_per_10000, that gives the number of Starbucks per 10,000 people. It is in the starbucks_with_2018_pop_est dataset.
census_pop_est_2018 <- read_csv("https://www.dropbox.com/s/6txwv3b4ng7pepe/us_census_2018_state_pop_est.csv?dl=1") %>%
separate(state, into = c("dot","state"), extra = "merge") %>%
select(-dot) %>%
mutate(state = str_to_lower(state))
## Rows: 51 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): state
## dbl (1): est_pop_2018
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
starbucks_with_2018_pop_est <-
starbucks_us_by_state %>%
left_join(census_pop_est_2018,
by = c("state_name" = "state")) %>%
mutate(starbucks_per_10000 = (n/est_pop_2018)*10000)
dplyr review: Look through the code above and describe what each line of code does. The first line with the read_csv is creating a new dataset, labeled census_pop_est_2018, and reading the data from the URL in. The second line with the separate function (the separate function separates a character variable into multiple variables) removes the dots from the state names. The state data was presented with period preceding the state name and this removes that so the data can be joined with another dataset. The select(-dot) function additionally helps us get rid of the period that precedes the state name. The mutate and str_to_lower function in the next line creates a new column in which the state name is presented as lowercase. The next line begins by creating a new dataset called starbucks_with_2018_pop_est. This new dataset will be created using left_join to join together starbucks_us_by_state with the census population data. We then mutate to add another column that gives us the number of starbucks (n) divided by the estimated population multiplied by 10,000 to allow us to understand the number of starbucks stores per 10,000 people. This accounts for the population of each state.
Create a choropleth map that shows the number of Starbucks per 10,000 people on a map of the US. Use a new fill color, add points for all Starbucks in the US (except Hawaii and Alaska), add an informative title for the plot, and include a caption that says who created the plot (you!). Make a conclusion about what you observe.
states_map <- map_data("state")
starbucks_with_2018_pop_est %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = n/est_pop_2018 * 10000)) +
geom_point(data = Starbucks %>% filter(`Country` == "US",
`State/Province` != c("HI", "AK")),
aes(x = Longitude, y = Latitude),
size = .05,
alpha = .2,
color = "goldenrod") +
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
labs(title = "Number of Starbucks in Each State per 10,000 People",
fill = "" ,
caption = "Created by Mackenzie Clarke") +
scale_fill_viridis_c(option = "green")
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option): Option
## 'green' does not exist. Defaulting to 'viridis'.
theme(legend.background = element_blank())
## List of 1
## $ legend.background: list()
## ..- attr(*, "class")= chr [1:2] "element_blank" "element"
## - attr(*, "class")= chr [1:2] "theme" "gg"
## - attr(*, "complete")= logi FALSE
## - attr(*, "validate")= logi TRUE
leaflet)Create a data set using the tibble() function that has 10-15 rows of your favorite places. The columns will be the name of the location, the latitude, the longitude, and a column that indicates if it is in your top 3 favorite locations or not. For an example of how to use tibble(), look at the favorite_stp_by_lisa I created in the data R code chunk at the beginning.
Create a leaflet map that uses circles to indicate your favorite places. Label them with the name of the place. Choose the base map you like best. Color your 3 favorite places differently than the ones that are not in your top 3 (HINT: colorFactor()). Add a legend that explains what the colors mean.
Connect all your locations together with a line in a meaningful way (you may need to order them differently in the original data).
If there are other variables you want to add that could enhance your plot, do that now.
mackenzie_fav_places <- tibble(
place = c("Hai Hai", "Macalester College", "Bent Paddle Brewery",
"Lake Harriet", "True North Ranch", "Pine Tree Apple Orchard",
"Minneapolis Institute of Art", "The Nook", "Superior Hiking Trail", "Home", "Half Moon Bay"),
long = c(-93.26259135894995, -93.16940235841348, -92.12048604141492,
-93.30612131724241, -92.85301775841815, -92.95486944306221, -93.27226162826636, -93.15650797005495,
-91.28751872625006, -122.22964936888202, -122.43151703438164),
lat = c(45.01013234302003, 44.934866690092, 46.7685422995477,
44.92265343749974, 44.82990649338687, 45.10689814136089,
44.965000416497965, 44.926752586283584, 47.31420997282805, 37.487084041256715, 37.4321523389281),
top_3 = c("No", "No", "Yes", "No", "No", "No", "No", "Yes", "No", "Yes", "No")
)
factpal <- colorFactor(topo.colors(3),
mackenzie_fav_places$top_3)
leaflet(data = mackenzie_fav_places) %>%
addTiles() %>%
addCircles(label = ~place,
lng = ~long,
lat = ~lat,
weight = 10,
opacity = 1,
color = ~factpal(top_3)) %>%
addPolylines(lat = ~lat,
lng = ~long,
color = col2hex("green")) %>%
addLegend(pal = factpal,
values = ~top_3,
opacity = 0.5,
title = "Top 3 Favorite Place?",
position = "bottomleft")
I ordered the points so that California, my home, connects to the Superior Hiking Trail, the first place I ever visited in Minnesota during my preorientation Macward Bound trip in the summer of 2018.
This section will revisit some datasets we have used previously and bring in a mapping component.
The data come from Washington, DC and cover the last quarter of 2014.
Two data tables are available:
Trips contains records of individual rentalsStations gives the locations of the bike rental stationsHere is the code to read in the data. We do this a little differently than usualy, which is why it is included here rather than at the top of this file. To avoid repeatedly re-reading the files, start the data import chunk with {r cache = TRUE} rather than the usual {r}. This code reads in the large dataset right away.
data_site <-
"https://www.macalester.edu/~dshuman1/data/112/2014-Q4-Trips-History-Data.rds"
Trips <- readRDS(gzcon(url(data_site)))
Stations<-read_csv("http://www.macalester.edu/~dshuman1/data/112/DC-Stations.csv")
## Rows: 347 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): name
## dbl (4): lat, long, nbBikes, nbEmptyDocks
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Stations to make a visualization of the total number of departures from each station in the Trips data. Use either color or size to show the variation in number of departures. This time, plot the points on top of a map. Use any of the mapping tools you’d like.joined_data_sets <- Trips %>%
left_join(Stations,
by=c("sstation"="name")) %>%
group_by(lat, long) %>%
summarize(n = n())
## `summarise()` has grouped output by 'lat'. You can override using the `.groups` argument.
washington_dc <- get_stamenmap(
bbox = c(left = -77.3586, bottom = 38.7523, right = -76.6603, top = 39.0361),
maptype = "toner-2010",
zoom = 11)
## Source : http://tile.stamen.com/toner-2010/11/583/782.png
## Source : http://tile.stamen.com/toner-2010/11/584/782.png
## Source : http://tile.stamen.com/toner-2010/11/585/782.png
## Source : http://tile.stamen.com/toner-2010/11/586/782.png
## Source : http://tile.stamen.com/toner-2010/11/587/782.png
## Source : http://tile.stamen.com/toner-2010/11/583/783.png
## Source : http://tile.stamen.com/toner-2010/11/584/783.png
## Source : http://tile.stamen.com/toner-2010/11/585/783.png
## Source : http://tile.stamen.com/toner-2010/11/586/783.png
## Source : http://tile.stamen.com/toner-2010/11/587/783.png
## Source : http://tile.stamen.com/toner-2010/11/583/784.png
## Source : http://tile.stamen.com/toner-2010/11/584/784.png
## Source : http://tile.stamen.com/toner-2010/11/585/784.png
## Source : http://tile.stamen.com/toner-2010/11/586/784.png
## Source : http://tile.stamen.com/toner-2010/11/587/784.png
ggmap(washington_dc) +
geom_point(data = joined_data_sets,
aes(x = long,
y = lat,
color = n),
alpha = 1,
size = .7) +
theme_map() +
scale_colour_viridis_c(option = "inferno") +
labs(title = "Total Number of Departures From Each Station",
fill = guide_legend("Number of Departures")) #this did not work and I could not figure out how to change the title of the legend.
## Warning: Removed 22 rows containing missing values (geom_point).
proportion_data <- Trips %>%
left_join(Stations,
by=c("sstation"="name")) %>%
group_by(lat, long) %>%
summarize(n = n(),
prop_casual = mean(client == "Casual"))
## `summarise()` has grouped output by 'lat'. You can override using the `.groups` argument.
proportion_data %>%
ggplot(aes(x = long,
y = lat,
color = prop_casual)) +
geom_point(shape = 17) +
labs(x = "Longitude",
y = "Latitude",
title = "Departures from Stations By Casual Users")
## Warning: Removed 1 rows containing missing values (geom_point).
ggmap(washington_dc) +
geom_point(data = proportion_data,
aes(x = long,
y = lat,
color = prop_casual),
alpha = 1,
size = .7) +
labs(title = "Departures From Stations By Casual Users") +
theme_map()
## Warning: Removed 22 rows containing missing values (geom_point).
The following exercises will use the COVID-19 data from the NYT.
states_map <- map_data("state")
state_covid <- covid19 %>%
group_by(state) %>%
slice_max(order_by = date,
n = 1) %>%
mutate(state_name = str_to_lower(state))
state_covid %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = cases)) +
#This assures the map looks decently nice:
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
labs(title = "Most Recent Cumulative COVID Cases By State",
fill = "Case Count",
caption = "Created by Mackenzie Clarke")
The problem with this map is that it does not account for the population of each state. This data is misleading because of this.
states_map <- map_data("state")
state_covid %>%
mutate(state_name = str_to_lower(state)) %>%
left_join(census_pop_est_2018,
by = c("state_name" = "state")) %>%
mutate(covid_10000 = (cases/est_pop_2018)*10000) %>%
group_by(state) %>%
slice_max(order_by = date,
n = 1) %>%
ggplot() +
geom_map(map = states_map,
aes(map_id = state_name,
fill = covid_10000)) +
#This assures the map looks decently nice:
expand_limits(x = states_map$long, y = states_map$lat) +
theme_map() +
labs(title = "Most Recent Cumulative COVID Cases By State",
fill = "Cases Per 10,000",
caption = "Created by Mackenzie Clarke")
These exercises use the datasets MplsStops and MplsDemo from the carData library. Search for them in Help to find out more information.
MplsStops dataset to find out how many stops there were for each neighborhood and the proportion of stops that were for a suspicious vehicle or person. Sort the results from most to least number of stops. Save this as a dataset called mpls_suspicious and display the table.data("MplsStops")
data("MplsDemo")
mpls_suspicious <- MplsStops %>%
group_by(neighborhood) %>%
mutate(stops = n(),
prop_suspicious = mean(problem == "suspicious")) %>%
arrange(desc(stops))
leaflet map and the MplsStops dataset to display each of the stops on a map as a small point. Color the points differently depending on whether they were for suspicious vehicle/person or a traffic stop (the problem variable). HINTS: use addCircleMarkers, set stroke = FAlSE, use colorFactor() to create a palette.factorpal <- colorFactor(topo.colors(5), MplsStops$problem)
leaflet(data = MplsStops) %>%
addTiles() %>%
addCircleMarkers(lng = ~long,
lat = ~lat,
label = ~neighborhood,
weight = 1,
opacity = 1,
stroke = FALSE,
color = ~factorpal(problem)) %>%
addLegend(pal = factorpal,
values = ~problem,
opacity = 0.5,
title = NULL,
position = "bottomleft")
eval=FALSE. Although it looks like it only links to the .sph file, you need the entire folder of files to create the mpls_nbhd data set. These data contain information about the geometries of the Minneapolis neighborhoods. Using the mpls_nbhd dataset as the base file, join the mpls_suspicious and MplsDemo datasets to it by neighborhood (careful, they are named different things in the different files). Call this new dataset mpls_all.mpls_nbhd <- st_read("Minneapolis_Neighborhoods/Minneapolis_Neighborhoods.shp", quiet = TRUE)
mpls_all <- mpls_nbhd %>%
left_join(mpls_suspicious,
by = c("BDNAME" = "neighborhood")) %>%
left_join(MplsDemo,
by = c("BDNAME" = "neighborhood"))
mpls_all
leaflet to create a map from the mpls_all data that colors the neighborhoods by prop_suspicious. Display the neighborhood name as you scroll over it. Describe what you observe in the map.palnumer <- colorNumeric("magma",
domain = mpls_all$prop_suspicious)
leaflet(data = mpls_all) %>%
addTiles() %>%
addCircles(lng = ~long,
lat = ~lat,
label = ~BDNAME,
color = ~palnumer(prop_suspicious)) %>%
addLegend(pal = palnumer,
values = ~prop_suspicious,
position = "bottomleft",
title = "Proportion Suspicious")
## Warning in validateCoords(lng, lat, funcName): Data contains 1 rows with either
## missing or invalid lat/lon values and will be ignored
There is a clear demarcation between neighborhoods in the proportion of suspicious police stops. I suspect that there is likely correlation between the neighborhoods with darker dots (majority traffic stops instead of suspicious stops) and the demographic of that neighborhood as it has been statistically suggested that police departments are more likely to stop people of color for suspicious violations.
leaflet to create a map of your own choosing. Come up with a question you want to try to answer and use the map to help answer that question. Describe what your map shows.palnumer <- colorNumeric("magma",
domain = mpls_all$prop_suspicious)
leaflet(data = mpls_all) %>%
addTiles() %>%
addCircles(lng = ~long,
lat = ~lat,
label = ~race,
color = ~palnumer(prop_suspicious)) %>%
addLegend(pal = palnumer,
values = ~prop_suspicious,
position = "bottomleft",
title = "Proportion Suspicious")
## Warning in validateCoords(lng, lat, funcName): Data contains 1 rows with either
## missing or invalid lat/lon values and will be ignored
Instead of coloring by neighborhood name, I colored by race in this map to see if I could identify any trends that I talked about in the previous problem (i.e if the areas with higher proportion suspicious stops was a larger demographic of people of color). This map is not perfect, but the results were interesting.
DID YOU REMEMBER TO UNCOMMENT THE OPTIONS AT THE TOP?